<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no" />
	<title>首页</title>
	<link rel="stylesheet" type="text/css" href="../c/aui.css" />
	<link rel="stylesheet" type="text/css" href="../c/swiper.min.css" />
	<link rel="stylesheet" type="text/css" href="../c/suxiangw.css" />
	<link rel="stylesheet" type="text/css" href="../c/animate.css" />
	<style media="screen">
		body {
			background-color: transparent;
			/*background:url('../i/loading_b.png');
				background-repeat: no-repeat;
				background-position: center;
				background-size: cover;*/
		}

		#t {
			position: fixed;
			top: 0;
			left: 0;
			width: 100%;
			height: 5rem;
			background-image: -webkit-linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0));
			background-image: -o-linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0));
			background-image: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0));
			z-index: 99999;
		}

		#b {
			position: absolute;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 15rem;
			z-index: 2;
			background-image: -webkit-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.4));
			background-image: -o-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.4));
			background-image: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.4));
		}

		#t .aui-pull-left {
			width: 2.5rem;
			height: 2.5rem;
			padding-top: 0.35rem;
			padding-left: 0.35rem;
		}

		#t .aui-pull-left img {
			padding: 0.5rem;
		}
		/*#t .aui-pull-left img{
				transform:rotate(180deg);
				margin:
			}*/

		#loadingdi {
			position: absolute;
			top: 0px;
			left: 0;
			right: 0;
			width: 2.5rem;
		}

		#log {
			position: fixed;
			left: 0;
			top: 2rem;
			z-index: 99999999;
			background: #000;
			height: 10rem;
			padding: 0.5rem;
			overflow: hidden;
		}

		#log p {
			color: #fff;
		}

		.fufei {
			position: absolute;
			top: 0;
			left: 0;
			z-index: 9999999;
			background-color: rgba(0, 0, 0, 0.8);
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			width: 100%;
			letter-spacing: 1.5px;
		}

		.fufei .t {
			font-size: 0.85rem;
		}

		.fufei div b {
			color: #FE2C55;
			padding-left: 0.25rem;
		}

		.fufei .b {
			display: flex;
			justify-content: space-between;
			margin-top: 2rem;
		}

		.fufei .b span {
			background: #555;
			border-radius: 5rem;
			padding: 0.35rem 1rem;
			font-size: 0.75rem;
			margin: 0 0.75rem;
		}

		.fufei .b span.c {
			background: #FE2C55;
		}
	</style>
</head>

<body>
	<!-- <div id="log"></div> -->
	<div id="t">
		<a class="aui-pull-left aui-hide" tapmode onclick="_closes()"><img src="../i/x.png" /></a>
	</div>
	<!-- <div id="loadingdi" style="top:{{= tblr}}px " class=""><img src="../i/footer_progress.png" /></div><div id="x" tapmode onclick="x({{= it[i].id}})"></div> -->
	<div class="swiper-container sx-index">
		<script id="sx-list" type="text/x-dot-template">
			{{ for(var i=0,it=it.data; i
			< it.length; i++) { }} <div class="swiper-slide suxiangw_img" id="id{{= it[i].id}}" data-data='{{= JSON.stringify(it[i])}}' {{? !api.pageParam[ 'data']}}style="background:url('../i/loading_b.png') no-repeat center center;background-size: cover;"
							{{?}} suxiangw-img="{{= _img(it[i].img,api.winWidth,api.winHeight,it[i].img?false:true) }}" data-money="{{= it[i].money}}">
				<div id="x" tapmode onclick="x({{= it[i].id}})"></div>
				<!-- <div id="loadingdi" style="top:{{= tblr}}px " class=""><img src="../i/footer_progress.png" /></div> -->
				<div class="pause_start aui-hide"></div>
				{{? it[i].money }}
				<div class="fufei" style="height:{{= api.winHeight}}px">
					<div class="t">观看视频需要<b>{{= it[i].money}}{{= _getPrefs('_config').zhibo.liwu_name}}</b></div>
					<div class="b">
						<span class="c" tapmode onclick="fufei({{= it[i].id}})">同意付款</span>
					</div>
				</div>
				{{?}}
				<div class="sx-right" style="padding-bottom:{{= api.safeArea.bottom}}px;{{? api.winName == 'index_video'}}bottom:0.75rem !important{{?}}">
					<div class="sx-user">
						<img tapmode onclick="_u({{= it[i].uid}})" src="{{= it[i].user.img ? _img(it[i].user.img,60,60) : '../i/touxiang.png' }}" /> {{? !it[i].member_guanzhu}}
						<em tapmode onclick="_guanzhu({{= it[i].uid}},this)"></em> {{?}}
					</div>
					<div class="sx-zan" tapmode onclick="_zan({{= it[i].id}})">
						<img src="../i/zan{{= it[i].user_zan?'-s':''}}.png" />
						<p>{{= it[i].zan_num }}</p>
					</div>
					<div class="sx-ping" tapmode onclick="_ping({{= it[i].id}},'{{= it[i].ping_num }}',true);">
						<img src="../i/ping.png" />
						<p>{{= it[i].ping_num }}</p>
					</div>
					<div class="sx-fen" tapmode onclick="fenxiang({{= it[i].id}})">
						<img src="../i/fen.png" />
						<p>分享</p>
					</div>
					<!--<div class="sx-yinyue-rigth">
							<div class="sx-yinyue-pang"><img src="{{= it[i].user.img ? _img(it[i].user.img,60,60) : '../i/touxiang.png' }}" /></div>
							<div class="sx-yinyue-img">
								<div class="video-music-i video-music-i1">
									<div><img src="../i/yinyue.png" /></div>
								</div>
								<div class="video-music-i video-music-i2">
									<div><img src="../i/yinyue.png" /></div>
								</div>
								<div class="video-music-i video-music-i3">
									<div><img src="../i/yinyue.png" /></div>
								</div>
							</div>
						</div>-->
				</div>
				<div class="sx-bottom" style="padding-bottom:{{= api.safeArea.bottom}}px;{{? api.winName == 'index_video'}}bottom:0.75rem !important{{?}}">
					<div class="sx-content">
						<div class="shop" tapmode onclick="_url({id:5},'shop_view_win')"><div class="a"><img src="../i/index_shop.png" ><span>同款视频</span></div></div>
						<div class="content-user-title" tapmode onclick="_u({{= it[i].uid}})"><span>@</span>{{= it[i].user.username}}</div>
						{{= _text(it[i].content) }}
					</div>
				</div>
				<div id="b"></div>
	</div>
	{{ } }}
	</script>
	<div class="swiper-wrapper" id="sx-view"></div>
	</div>
</body>
<script type="text/javascript" src="../j/_video.js"></script>
<script type="text/javascript" src="../j/swiper.min.js"></script>
<script type="text/javascript" src="../j/api.js"></script>
<script src="../j/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
	var mySwiper, ping_x = false,
		v_data, activeIndex = 5,
		sid = 0,
		thisActiveIndex = 0,
		tblr = 0;
	// 数量
	apiready = function() {
		urls();
			if(adName){
	_init_ad();
	ad = api.require(adName);
}

			if (api.winName == 'root') {
				_v_frameName = 'suxiangw_com'
			}
			tblr = api.winHeight / 2.3;
			// console.log(tblr)
			api.bringFrameToFront({
				from: 'index_header',
			});
			api.bringFrameToFront({
				from: 'index_footer',
			});
			if (api.winName == 'index_video') {
				$('#t a').removeClass('aui-hide');
				$api.fixStatusBar($api.dom('#t a'))
			}

			//	console.log(api.frameName)
			api.execScript({
				frameName: 'root',
				script: 'getTotalUnreadCount();'
			});
			// $api.fixTabBar($api.byId('sx-footer'))
			// 回到屏幕
			api.addEventListener({
				name: 'viewappear'
			}, function(ret, err) {
				// 暂时后播放视频
				_start();
				pause_start(1);
			});
			// 离开屏幕
			api.addEventListener({
				name: 'viewdisappear'
			}, function(ret, err) {
				// 暂停视频
				pause_start();
				_pause();
			});
			//应用进入后台事件
			api.addEventListener({
				name: 'pause'
			}, function(ret, err) {
				_pause();
				pause_start();
				// 暂停视频
				//	_pause();
			});
			// 应用从后台回到前台事件
			api.addEventListener({
				name: 'resume'
			}, function(ret, err) {
				// 暂时后播放视频
				_start();
				pause_start(1);
			});

			video_list();
			api.addEventListener({
				name: 'ping_win'
			}, function(ret, err) {
				console.log(JSON.stringify(ret.value));
				if (ret.value.swiping_show == true) {
					swiping_show();
				}
			});
			// 监听倒计时开关
			api.addEventListener({
				name: 'time_jinbi'
			}, function(ret, err) {
				alert(JSON.stringify(ret.value));
				if (ret.value.time_jinbi == true) {
					yuandu();
				} else {
					api.closeFrame({
						name: 'time'
					});
				}
			});

		}
		// 判断是否video_list打开
	function video_list() {
		if (api.pageParam['data']) {
			v_data = api.pageParam['data'];
			if (api.pageParam['member'] == 'xihuan') {
				sid = '';
			} else {
				sid = v_data.id + '/suid/' + api.pageParam['member_id'];
			}
			// console.log(api.pageParam['name'])
			_play(v_data.url)
			var ret = {
				"data": [v_data]
			};
			//渲染模版
			var evalData = doT.template($api.html($api.byId('sx-list')));
			$api.html($api.byId('sx-view'), evalData(ret));
			$api.fixTabBar($api.dom('.sx-index .sx-right'))
			$api.fixTabBar($api.dom('.sx-index .sx-bottom'))
		}
		data();
		//	data();
	}
	var time_jinbi = true;

	function data(msg) {
		// alert(sid)
		// 先显示上一次大图
		//		video_img_t();
		if (msg) {
			_loading('刷新中...');
		}
		_ajax('video/lists/limit/3/sid/' + sid, function(ret, err) {
			if (msg) {
				_loadingCloes();
			}
			if (ret) {
				if (msg) {
					_msg('推荐' + ret.data.length + '条视频更新')
				}
				// if(ret.data.length){
				// 	for (var i = 0; i < ret.data.length; i++) {
				// 		if(ret.data[i].url){
				// 		//	download(ret.data[i].url);
				// 		}
				// 	}
				// }
				if (!ret.total) {
					return;
				}
				v_data = ret.data[0];
				if (api.frameName == 'index_list_0') {
					_play_url(v_data.url);
				} else {
					if (!api.pageParam['data']) {
						_play(v_data.url)
					}
				}
				// 增加播放次数
				_click(v_data.id);
				api.refreshHeaderLoadDone();

				//渲染模版
				var evalData = doT.template($api.html($api.byId('sx-list')));
				if (api.pageParam['data']) {
					$api.append($api.byId('sx-view'), evalData(ret));
				} else {
					$api.html($api.byId('sx-view'), evalData(ret));
				}
				// if(time_jinbi){
				// 	yuandu();
				// 	time_jinbi = false;
				// }
				api.parseTapmode();
				imageCache();

				// 执行滑动
				mySwiper = new Swiper('.swiper-container', {
					// preventInteractionOnTransition : true,	// 在过渡时将无法滑动
					direction: 'vertical',
					noSwiping: true,
					preventClicksPropagation: false,
					preventClicks: false,
					on: {
						reachEnd: function() {
							addSlide();
						},
						// touchStart:function(e){
						// 	console.log('touchStart')
						// 	 clearTimeout(timeID);
						// },
						// setTransition:function(){
						// 	console.log('setTransition')
						// 	clearTimeout(timeID);
						// },
						// touchMove : function(event) {
						// 	console.log('touchMove')
						// 	clearTimeout(timeID);
						// },
						slideChangeTransitionEnd: function() {
							thisActiveIndex = this.activeIndex;
							video_init();
							api.execScript({
								frameName: 'time',
								script: 't(' + false + ');'
							});

						},
					},
				});

			} else {
				_alert(JSON.stringify(err))
				$api.html($api.byId('sx-view'), "<div class='aui-text-center aui-margin-15'>" + err.msg + "</div>");
			}
			// $('#x').on('tap', function () {
			// 	clearTimeout(timer);
			// });
			// touch.on('.swiper-slide', 'doubletap', function (e) {
			// 	_zan(v_data.id);
			// });
			setTimeout(function() {
				if (ad_vip) {
					_url({
						animation: true,
						js: 'kaiping',
						time_jinbi: time_jinbi,
						time_jinbi_name: api.winName,
						time_jinbi_frameName: api.frameName
					}, 'ad');
				}
			}, 1000);
		})
	}

	function video_init() {

		// 先显示上一次大图
		video_img_t();
		//	console.log('滑动位置：'+thisActiveIndex)
		var a_this = $('.swiper-slide-active');
		var data = a_this.data('data');
		v_data = data;
		if (_getPrefs('_config').config.app == 1) {
			if (_getPrefs('yinbi' + v_data.id)) {
				api.alert({
					msg: '视频已隐蔽，无法欢看',
					buttons: ["下一个"]
				}, function(ret, err) {
					if (ret) {
						_slideNext();
					} else {
						alert(JSON.stringify(err));
					}
				});

				return;
			}
		}
		// 判断欢看限制
		if (_is_video()) {
			_suxiangw_msg();
			return;
		}
		// 判断结束
		// 记录 播放次数

		// 移除暂停图标
		pause_start(1);
		// 播放视频
		_play_url(v_data.url);
		// 增加播放次数
		_click(v_data.id);

		// 判断是否超出数量
		//	removeSlide();
		if (thisActiveIndex >= activeIndex) {
			//	console.log('加载新数据')
			// 添加新数据
			// addSlide();
		}
	}
	// 移除背影大图
	var timeID

	function video_img() {
		var video_money = $('#id' + v_data.id).data('money');
		if (video_money && video_money != 0) {
			_pause();
			return;
		}
		pause_start(1);
		timeID = setTimeout(function() {
			// background:url('{{= _img(it[i].img,api.winWidth,api.winHeight,it[i].img?false:true) }}') no-repeat center center;background-size: cover;
			// // 显示上一个封面大图
			// var _this = $('.swiper-slide-prev');
			// var img = _this.attr('suxiangw-img');
			// _this.attr('style','background:url("'+img+'") no-repeat center center;background-size: cover;');
			//
			// // 显示下一个封面大图
			// var _this = $('.swiper-slide-next');
			// var img = _this.attr('suxiangw-img');
			// _this.attr('style','background:url("'+img+'") no-repeat center center;background-size: cover;');
			// 移除屏幕封面大图
			var _this = $('.swiper-slide-active');
			// console.log($('#sx-view').html());
			// console.log(_this.html());
			_this.removeAttr('style');
			_this.data('style', 1);
		}, 300)

	}
	// 显示上一个封面大图
	function video_img_t() {
		var srcs = $('[data-style]')
		if (srcs.length) {
			for (var i = 0; i < srcs.length; i++) {
				(function(imgObj) {
					var img = imgObj.attr('suxiangw-img');
					imgObj.attr('style', 'background:url("' + img + '") no-repeat center center;background-size: cover;');
					imgObj.removeAttr('data-style');
					imgObj.children('#loadingdi').removeClass('aui-hide');
				})($(srcs[i]));
			}
		}
	}
	// 播放器开关
	function pause_start(a) {
		if (!v_data) {
			return;
		}
		var _this = $('#id' + v_data.id + ' .pause_start');
		if (!a) {
			_this.removeClass('aui-hide');
			_this.addClass('animated bounceIn');
			_this.one('webkitAnimationEnd',  function(ret) {
				_this.removeClass('animated bounceIn');
			});
		} else {
			_this.removeClass('animated bounceIn');
			_this.addClass('aui-hide');
		}
	}
	// 关闭 暂停 恢复
	var x_time_l = 0;
	var x_time_r = 0;

	function x() {
		// var myDate = new Date();
		// x_time_l = parseInt(myDate.getTime());
		// if(x_time_l < x_time_r){
		// 	return console.log('双击了');
		// }
		// x_time_r = x_time_l+300;
		// console.log(x_time_l+":"+x_time_r);
		// return;
		var ping_x = $('.swiper-slide-active').hasClass('swiper-no-swiping');
		if (ping_x) {
			// 关闭评论窗口
			api.execScript({
				frameName: 'ping_win',
				script: 'x("' + api.frameName + '")'
			});
		} else {
			_x(v_data.id);
		}
	}
	// 右侧用户资料更新
	// function indexUserInfo(){
	// 	api.execScript({
	// 			frameName: 'member',
	// 			script: "indexUserInfo('"+JSON.stringify(v_data)+"')"
	// 	});
	// }
	// 打开右侧用户
	// function right(){
	// 	api.setFrameGroupIndex({
	// 	    name: 'index',
	// 	    index: 1,
	// 			scroll:true,
	// 	});
	// }

	// 滑动最后增加数据
	var addSlide_ajax = false;
	var page = 1;

	function addSlide() {
		if (addSlide_ajax) {
			return;
		}
		addSlide_ajax = true;
		chaping();

		//_url({animation:true,js:'kaiping'},'ad');
		//quanping();
		//	_loading();
		//	console.log('api/article/lists/mychannel/4/ids/'+sx.id+'/?page='+page);
		_ajax('video/lists/limit/3/sid/' + sid + '/page/' + page, function(ret, err) {
			if (ret) {
				var data = ret.data;
				for (var i = 0; i < data.length; i++) {
					download(data[i].url);
					var evalData = doT.template($api.html($api.byId('sx-list')));
					var ret = {
						"data": [data[i]]
					};
					mySwiper.appendSlide(evalData(ret));
				}
				imageCache();
				var len = $('.swiper-slide').length;
				activeIndex = activeIndex + 10;
				if (len > 15) {
					//	activeIndex = activeIndex > 25 ? (activeIndex + 10) : 25;
				}
				api.parseTapmode();
				//	console.log('当前总共有：'+len+'条数据');
			}
			addSlide_ajax = false;
			page = page + 1;

			//	_loadingCloes();
			//	_msg('已为您推荐'+data.length+"条视频")
		})

	}
	// 图片缓存本地
	function imageCache() {
		var srcs = $(".suxiangw_img");
		if (srcs.length > 0) {
			for (var i = 0; i < srcs.length; i++) {
				(function(imgObj) {
					var imgUrl = imgObj.attr("suxiangw-img");
					if (imgUrl.indexOf('undefined') == -1) {
						api.imageCache({
							url: imgUrl,
							thumbnail: false
						}, function(ret, err) {
							if (ret) {
								if (!ret.status) {
									ret.url = imgUrl
								}
								imgObj.attr('style', 'background:url("' + ret.url + '") no-repeat center center;background-size: cover;');
								imgObj.attr("suxiangw-img", ret.url);
								imgObj.removeClass('suxiangw_img');
							}
						});
						//	video_img();
					}
				})($(srcs[i]));
			}
		}
	}
	// 播放当前视频
	function pay_url() {
		//	console.log(JSON.stringify(v_data));
		_play_url(v_data.url);
	}
	// 分享
	function fenxiang(vid) {
		var data = $('#id' + vid).data('data');
		_fenxiang(data);
	}
	// // 获取指定视频信息
	// function video_view(vid){
	// 	_ajax('video/view',function(ret,err){
	// 		if(ret){
	// 			if(ret.err){
	// 				return _alert(ret.err);
	// 			}else{
	// 				return
	// 			}
	// 		}
	// 	})
	// }
	function htmls() {
		console.log($('body').html());
	}
	// 刷新数据
	function shuaxin() {
		return;
		removeSlide();
		addSlide();
	}
	// 删除
	function removeSlide() {
		var len = $('.swiper-slide').length;
		for (var i = 0; i < len; i++) {
			mySwiper.removeSlide(0);
		}
	}
	// 关闭
	function _closes() {
		api.execScript({
			script: '_closes();'
		})
	}
	// loading——video
	function video_loading(a) {
		return;
		var _this = $('#id' + v_data.id + ' #loadingdi');
		if (a) {
			_this.removeClass('aui-hide');
		} else {
			_this.addClass('aui-hide');
		}
	}
	// 打开奖励圆度倒计时
	function yuandu() {
		if (!_getPrefs('_config').time_show) {
			return;
		}
		_ajax('renwu/time_jinbi', function(ret, err) {
			if (ret) {
				if (ret.ret) {
					time_jinbi = false;
					url = 'time';
					var y = parseInt($('.sx-user').eq(0).offset().top) - 180;
					api.openFrame({
						name: url,
						url: _h_w + url + '.html',
						rect: {
							x: api.winWidth - 66,
							y: y,
							w: 58,
							h: 168,
						},
						bgColor: 'rgba(0,0,0,0)',
					})
				}
			}
		})
	}
	// 付费视频观看
	function fufei(id) {
		if(!_getPrefs('_token',true)){
			return _login();
		}
		_loading('正在请求');
		_ajax('member/video_money', function(ret, err) {
			_loadingCloes();
			if (ret) {
				if (ret.ret) {
					_suxiangw_msg2({
						rightTitle: '立刻观看视频',
					}, function(ret) {
						if (ret.eventType == 'right') {
							$('#id' + v_data.id).data('money', '');
							$('#id' + v_data.id + ' .fufei').hide();
							video_img();
							_start();
							pause_start(1);
						}
						dialogBox.close({
							dialogName: 'alert'
						});
					});
				} else {
					_suxiangw_msg({
						content: ret.err,
						rightTitle: '充值'
					}, function(ret) {
						console.info(JSON.stringify(ret));
					});
				}
			}
		}, {
			vid: id
		})
	}
</script>

</html>
